<template>
  <div class="container-home">
    <form action="/">
      <van-search
        style="position: fixed; width: 100%; top: 0; z-index:2"
        v-model="value"
        background="#E7EAED"
        show-action
        placeholder="请输入搜索关键词"
        @input="onSearch"
        @cancel="onCancel"
      />
    </form>
    <van-row
      style="padding: 8px"
      v-for="(item, index) in adList"
      :key="item.id"
     
    >
      <div class="card-top" @click="toMaterialByRouter(item.link)">
        <img :src="item.url" v-if="index === 0" height="168px" width="100%" />
        <img v-else :src="item.url" height="254px" width="100%" />
      </div>
    </van-row>
    <van-grid :column-num="2" :border="false" :clickable="true">
      <van-grid-item
        v-for="item in options"
        :key="item.id"
        @click="toMaterial(item.id)"
      >
        <!-- <template slot="content"> -->

        <div class="card">
          <img
            v-lazy="item.imgUrl"
            alt="item.tagName"
            style="width: 100%"
            height="180px"
            width="180px"
          />
          <div class="buju">
            <van-row class="box_big">
              <van-col>{{ item.tagName }}</van-col>
              <van-col>{{ item.des }}</van-col>
            </van-row>
          </div>
          <!-- class="span_top" class="span_bot" -->
        </div>

        <!-- </template> -->
      </van-grid-item>
    </van-grid>
  </div>
</template>

<script>
import { Grid, GridItem, Row, Col, Image, Search, Toast } from 'vant';
import { tagList } from '@/api/api';
export default {
  data() {
    return {
      options: [],
      adList: [],
      value: '',
    };
  },
  created() {
    this.getTagList();
  },
  methods: {
    onSearch(val) {
      tagList({
        status: 1,
        sort: 'sort_order',
        order: 'asc',
        keywords: val,
      }).then((res) => {
        this.options = res.data.data.tagList;
        this.adList = res.data.data.adList;
        //alert(JSON.stringify(this.adList))
      });
      if (val == '') {
        tagList({ status: 1, sort: 'sort_order', order: 'asc' }).then((res) => {
          this.options = res.data.data.tagList;
          this.adList = res.data.data.adList;
          //alert(JSON.stringify(this.adList))
        });
      }
    },
    onCancel() {
      tagList({ status: 1, sort: 'sort_order', order: 'asc' }).then((res) => {
        this.options = res.data.data.tagList;
        this.adList = res.data.data.adList;
        //alert(JSON.stringify(this.adList))
      });
    },

    getTagList() {
      tagList({ status: 1, sort: 'sort_order', order: 'asc' }).then((res) => {
        this.options = res.data.data.tagList;
        this.adList = res.data.data.adList;
        //alert(JSON.stringify(this.adList))
      });
    },
    toMaterial: function (tagId) {
      //alert(tagId)
      this.$router.push({
        path: '/material/goodsMaterial',
        query: { tagId: tagId },
      });
    },
    toMaterialByRouter: function (detail) {
      this.$router.push({
        path: detail,
      });
    },
  },
  components: {
    [Grid.name]: Grid,
    [GridItem.name]: GridItem,
    [Row.name]: Row,
    [Col.name]: Col,
    [Image.name]: Image,
    [Search.name]: Search,
    [Toast.name]: Toast,
  },
};
</script>

<style scoped lang="scss">
.flex {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}
.flex-v {
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
}
.flex-1 {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
}
.flex-align-center {
  -webkit-box-align: center;
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
}
.flex-pack-center {
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
}
.flex-pack-justify {
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  -ms-flex-pack: justify;
  justify-content: space-between;
}
img {
  display: block;
}
.box_big {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 70px;
  width: 100%;
  padding: 0 4%;

  .van-col:nth-child(1) {
    font-weight: 700;
    width: 100%;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
  }
  .van-col:nth-child(2) {
    color: #929292;
    width: 100%;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    line-height: 20px;
  }
}

.card {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
  width: 100%;
  height: 250px;
  border-radius: 5px;
}

.card-top {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
  border-radius: 5px;
}

.card:hover {
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}

img {
  border-radius: 5px 5px 0 0;
}

.container-home {
  padding-top:2.5rem;
  background: white;
}

.van-grid-item >>> .van-grid-item__content {
  padding: 8px;
}
</style>
